#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N =1000;
ll n,m,h[N],idx,e[N],ne[N],d[N];
bool vis[N];	vector<ll> ans;
void add(ll a,ll b)
{
	e[idx]=b;
	ne[idx]=h[a];
	h[a]=idx++;
}
void init()
{
	memset(vis,false,sizeof vis);
	memset(h,-1,sizeof h);
	idx=0;
	ans.clear();
	memset(d,0,sizeof d);
}
void topsort()
{
	queue<ll> q;
	for(ll i=1;i<=n;i++)
	{
		if(d[i]==1)
		{
			q.push(i);
		}
	}
	while(!q.empty())
	{
		auto a=q.front();
		q.pop();
		d[a]=0;
		for(ll i=h[a];i!=-1;i=ne[i])
		{
			ll b=e[i];
			d[b]--;
			if(d[b]==1)
			{
				q.push(b);
			 } 
		}
	}
}
ll dfs(ll st,ll ed,ll a,ll cnt)
{
	ll res=cnt;
    
	for(ll i=h[a];i!=-1;i=ne[i])
	{
		ll b=e[i];
		if(!vis[b])
		{
            vis[b]=true;
			dfs(st,ed,b,cnt+1);
		}
		
	}
    ans.push_back(res);
	return res;
}
int main()
{
	ll t;
	cin >> t;
	while(t--)
	{
		init();
	
		cin >> n >> m;
		for(ll i=1;i<=m;i++)
		{
			ll a,b;
			cin >> a >> b;
			add(a,b),add(b,a);
			d[a]++,d[b]++;
		}
		topsort();
		for(ll i=1;i<=n;i++)
		{
			if(d[i]==2&&!vis[i])
			{
				ll st=i,ed=e[h[i]];
				vis[st]=vis[ed]=true;
				//cout<<st<<"<"<<ed<<endl; 
				ans.push_back(dfs(st,ed,i,1));
			}
		}
		sort(ans.begin(),ans.end());
		cout<<ans[ans.size()-1]<<" "<<ans[ans.size()-2]<<"\n";
	}
}
